package ecitys.gcs

import ecitys.types.Money;

class Indice {
	String indice
	
	Money getCurrentValue(){
		def result = ValorIndice.executeQuery("Select v.valor from ValorIndice v where v.indice=? and v.dataDeVigencia=(Select max(dataDeVigencia) from ValorIndice v2)",this)
		result ? result.get(0) : Money.newMoneyFromReal(0)
	}

    String toString(){
		indice
	}
	
	static transients = ['currentValue']
		
	static hasMany = [valorIndice : ValorIndice]
	
	static mapping = {
		table schema:"gcs"
	}
	
	static constraints = {
		indice(maxSize:30, blank:false, unique:true, nullable:false)
    }
}
